package com.cntcdt.api.db.dao;

import java.util.List;

import com.cntcdt.api.db.dao.base.GroupDemoDeviceDaoBase;
import com.cntcdt.api.db.model.GroupDemoDeviceModel;

/**
 * 这是cdt_group_demo_device的Dao实现类
 */
public class GroupDemoDeviceDao extends GroupDemoDeviceDaoBase   {
    /**
     * GroupDemoDeviceDao对象
     */
    private static GroupDemoDeviceDao instance = new GroupDemoDeviceDao();

    /**
     * 默认构造方法
     */
    private GroupDemoDeviceDao() {
    }

    /**
     * 获得对象实例
     */
    public static GroupDemoDeviceDao getInstance() { 
         return instance;
    } 
    
    public GroupDemoDeviceModel findByGroupIdAndTermianl(String terminal,int groupId) {
        String sql = "SELECT * FROM " + TABLE + " WHERE terminal = ? and groupId = ? and opStatus = 0";
       Object[] paramObjs = {terminal,groupId};
       List<GroupDemoDeviceModel > modelList = this.queryModelList(sql, paramObjs);
       if(modelList != null && modelList.size() > 0){ 
             return  modelList.get(0);
       } 
       return null;
   }
    
    public List<GroupDemoDeviceModel> findBySortTime(int sortTime, int groupId) {
    	sortTime = sortTime*20;
        String sql = "SELECT * FROM " + TABLE + " WHERE groupId = ? and opStatus = 0 limit ?,20";
       Object[] paramObjs = {groupId,sortTime};
       List<GroupDemoDeviceModel > modelList = this.queryModelList(sql, paramObjs);
       return modelList;
   }
    
    public List<GroupDemoDeviceModel> findByAllDevice(int groupId) {
        String sql = "SELECT * FROM " + TABLE + " WHERE groupId = ? and opStatus = 0";
       Object[] paramObjs = {groupId};
       List<GroupDemoDeviceModel > modelList = this.queryModelList(sql, paramObjs);
       return modelList;
   }

}
